// 获取数据
import Vue from 'vue';
import router from '@/router'
let vm = new Vue();
var _this = vm
/**
 * object  
 * require 是否为true ，
 * title 提示文字
 * name  提示前的文字 请输入或请选择
 * **/
export function require(object, name, submit) {
  if (object.require == true && (String(submit[object.field]) == '' || submit[object.field] == undefined)) {
    _this.$message.error(name + object.title);
    return false
  }
}

export function pageFlow(page,callBack){
  _this.$axios.get('/open/page/flow',{params:{
      userType:sessionStorage.getItem('userType'),
      isModify:Number(sessionStorage.getItem('isModify')),
      pageId:page,
  }})
  .then(function (res) {
    callBack(res)
  })
  .catch(function (error) {
    console.log(error);
  });
}

export function BtnsFlow(page,callBack){
  _this.$axios.get('/open/page/flow',{params:{
    userType:sessionStorage.getItem('userType'),
    isModify:Number(sessionStorage.getItem('isModify')),
    pageId:page
  }})
  .then(function (res) {
    callBack(res)
  })
  .catch(function (error) {
    console.log(error);
  });
}

export function uploads(data,callBack){
  _this.$axios.post("/common/uploads",data)
  .then(function (res) {
    callBack(res)
  })
  .catch(function (error) {
    console.log(error);
  });
}

export function analyse(data,callBack){
  _this.$axios.post("/common/analyse",data)
  .then(function (res) {
    
    callBack(res)
  })
  .catch(function (error) {
    console.log(error);
  });
}

export function submit(data,callBack){
  _this.$axios.post("/open/page/submit",data)
  .then(function (res) {
    callBack(res)
  })
  .catch(function (error) {
    console.log(error);
  });
}

// 获取下标
export function getsubscript(obg){
  // console.log(obg.page_flow,obg.page_info.id,'xiabioao')
  var num = obg.page_flow.findIndex((item) => item == obg.page_info.id)
  // console.log(num,'xiabioao')
  return num
}

export function backTitle(text,href,show){
  var htmlStr   = text;
  href = href || 'autograph'
  show = show?show:false;
  var toHref = (router.mode=='hash'?'#/'+href:'/'+href)
  var reg0 = new RegExp("#.*?#", "g");
  var array = htmlStr.match(reg0);
  let content = htmlStr;
  if(array && array.length !==0){
      for (let index = 0; index < array.length; index++) {
          const element = array[index];
          var  str = element.replace(/#/g,'')
          if(show){
              content = content.replace(element,`<a href="${toHref}"  class="blueColor">${str}</a>`)
          }else{
              content = content.replace(element,`<span  class="blueColor isClick">${str}</span>`)
          }
      }
  }
  return content
};